import 'package:flutter/material.dart';

class PriceWidget extends StatelessWidget {
  const PriceWidget({
    this.price = '',
    this.color,
    this.symbolFontSize,
    this.integerFontSize,
    this.decimalFontSize,
    this.fontWeight,
    super.key,
  });

  final String price;
  // 价格的颜色
  final Color? color;
  // 价格符号部分的字号
  final double? symbolFontSize;
  // 价格整数部分的字号
  final double? integerFontSize;
  // 价格小数部分的字号
  final double? decimalFontSize;
  // 粗体
  final FontWeight? fontWeight;

  @override
  Widget build(BuildContext context) {
    return RichText(
      text: TextSpan(
        text: '￥',
        style: TextStyle(
          fontSize: symbolFontSize ?? 9,
          color: color ?? Color(0xFFff4400),
          fontWeight: fontWeight ?? FontWeight.w600,
        ),
        children: [
          TextSpan(
            text: price.split('.')[0],
            style: TextStyle(fontSize: integerFontSize ?? 13),
          ),
          TextSpan(
            text: '.${price.split('.')[1] ?? '00'}',
            style: TextStyle(fontSize: decimalFontSize ?? 12),
          ),
        ],
      ),
    );
  }
}
